package com.cat.dynamicPlanning02;

/**
 * @author 曲大人的喵
 * @description https://leetcode.cn/problems/number-of-subarrays-with-bounded-maximum/
 * @create 2025/11/4 15:49
 * @since JDK17
 */

public class Solution31 {
    static int[] deque = new int[((int) (1e5 + 10))];
    public int numSubarrayBoundedMax(int[] nums, int left, int right) {
        int ans = 0, h = 0, t = 0, n = nums.length, max = 0, last = 0;
        for (int l = 0, r = 0; r < n; r++) {
            max = Math.max(max, nums[r]);
            if (nums[r] >= left && nums[r] <= right) {
                last = r;
            }
            if (left <= max && max <= right) {
                ans += r - last + 1;
            }
            if (max > right) {
                l  = last = r + 1;

            }
        }

        return ans;
    }
}
